package vnc.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class UDPbit extends JPanel{

	String[] names;
	Object[] values;
	
	Point LocationBox = new Point(0,0);
	Dimension PaneSize = new Dimension(600,150); 
	
	JLabel jl= new JLabel();
	
	JButton SourcePort;
	JButton DestinationPort;
	JButton Length;
	JButton Checksum;
	
	
	
	public UDPbit(){
		
		SourcePort = new JButton("Socure Port");
		DestinationPort = new JButton("Destination Port");
		Length = new JButton("Length");
		Checksum = new JButton("Checksum");


		this.setLayout(null);
		this.setBackground(Color.white);

		this.removeBoxBorder(SourcePort);
		this.removeBoxBorder(DestinationPort);
		this.removeBoxBorder(Length);
		this.removeBoxBorder(Checksum);
		
		SourcePort.setBackground(new Color(0x99,0xff,0x66));
		DestinationPort.setBackground(new Color(0x99,0xff,0x66));
		Length.setBackground(new Color(0xcc,0xff,0x66));
		Checksum.setBackground(new Color(0xcc,0xff,0x66));
		
		this.add(SourcePort);
		this.add(DestinationPort);
		this.add(Length);
		this.add(Checksum);
	
		jl.setBounds(0, 160, 600, 120);
		this.add(jl);
	}
	
	
	public static void removeBoxBorder(JButton box){
		box.setBorderPainted(true);
		box.setContentAreaFilled(true);
		box.setDefaultCapable(false);
		box.setFocusPainted(false);
	}
public void getInfos(final String[] names,final Object[] values){
		
		
	
		this.names = names;
		this.values = values;
		Font f = new Font("",Font.BOLD,13);
		jl.setFont(f);
		
		
		SourcePort.setBounds(LocationBox.x, LocationBox.y,PaneSize.width/2, PaneSize.height/5);
		SourcePort.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[0]+" : "+values[0]);
			}
		});
		
		DestinationPort.setBounds(LocationBox.x + SourcePort.getWidth(), LocationBox.y,PaneSize.width/2, PaneSize.height/5);
		DestinationPort.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[1]+" : "+values[1]);
			}
		});
		Length.setBounds(LocationBox.x, LocationBox.y+SourcePort.getHeight(),PaneSize.width/2, PaneSize.height/5);
		Length.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[2]+" : "+values[2]);
			}
		});
		Checksum.setBounds(LocationBox.x+Length.getWidth(), LocationBox.y+SourcePort.getHeight(),PaneSize.width/2, PaneSize.height/5);
		Checksum.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText("nothing");
			}
		});
	}


public String isProtocol() {
	// TODO Auto-generated method stub
	return "UDP";
}

public void onPane() {
	this.setVisible(true);
	
}

public void offPane() {
	// TODO Auto-generated method stub
	this.setVisible(false);
	
}

}
